/*

定义栈的数据结构，请在该类型中实现一个能够得到栈的最小元素的 min 函数在该栈中，调用 min、push 及 pop 的时间复杂度都是 O(1)。
*/

#include <iostream>
#include <stack>
#include <set>

using namespace std;

class CQueue {
public:

    stack<int> s;
    set<int> s1;
    MinStack() {

    }
    
    void push(int x) {
        s.push(x);
		s1.insert(x);
    }
    
    void pop() {
        int top = s.top();
		s1.erase(top);
        s.pop();
    }
    
    int top() {
		return s.top();
    }
    
    int min() {
		return *s1.begin();
    }
	
	void show(){
		auto tmp = s;
		while(!tmp.empty()){
			int t = tmp.top();
			cout << t << ",";
			tmp.pop();
		}
		cout << endl;
	}
};

/**
 * Your CQueue object will be instantiated and called as such:
 * CQueue* obj = new CQueue();
 * obj->appendTail(value);
 * int param_2 = obj->deleteHead();
 */
 
int main(){
	CQueue* obj = new CQueue();
	obj->push(1);
	obj->push(2);
	obj->push(3);
	obj->push(NULL);
	obj->push(4);
	obj->show();
	cout << "min:" << obj->min() << endl;
	obj->pop();
	obj->show();
	cout << "min:" << obj->min() << endl;
	obj->push(-10);
	obj->show();
	cout << "min:" << obj->min() << endl;
	
	
	return 0;
}